/*
The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
Find the sum of all the primes below two million.

Anser:142913828922
Time:11.480511ms
*/
package main

import (
	"fmt"
	"time"
)

// copy:https://projecteuler.net/thread=10;page=8
// 我自己写的算法，类似7.go，大约需要1.5min，太慢
func main() {
	tstart := time.Now()
	const bound = 2e6
	sum := 0
	sieve := make([]bool, bound)
	for i := 2; i < bound; i++ {
		if sieve[i] {
			continue
		}

		for j := 2 * i; j < bound; j += i {
			sieve[j] = true
		}

		sum += i
	}
	fmt.Println(sum)
	tend := time.Now()
	fmt.Println(tend.Sub(tstart))
}
